<template>
  <div>
    <el-row style="margin-bottom:20px;display:flex;justify-content:flex-start">
      <el-select v-model="searchData.ttype" placeholder="请选择培训形式" style="margin-right:10px" clearable>
        <el-option
          v-for="item in ttypeArr"
          :key="item.value"
          :label="item.hash.code_name"
          :value="item.hash.code_id"
        ></el-option>
      </el-select>
      <el-select v-model="searchData.has_cert" placeholder="请选择是否取证" style="margin-right:10px" clearable>
        <el-option
          v-for="item in ishashArr"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        ></el-option>
      </el-select>
      <el-select v-model="searchData.isbegin" placeholder="请选择计划状态" style="margin-right:10px" clearable>
        <el-option
          v-for="item in isbeginArr"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        ></el-option>
      </el-select>
      <el-input placeholder="培训内容" style="width:15%" v-model="searchData.tcontent" clearable></el-input>
      <el-date-picker
        v-model="pre_beginyear"
        style="margin:0 10px;"
        type="year"
        valueFormat="yyyy"
        placeholder="选择计划年度"
      >
      </el-date-picker>
      <!-- <el-date-picker
        clearable
        v-model="plandate"
        type="daterange"
        style="margin:0 10px;"
        rangeSeparator="至"
        startPlaceholder="培训开始日期"
        endPlaceholder="培训开始日期"
        valueFormat="yyyy-MM-dd"
      ></el-date-picker>
      <el-date-picker
        clearable
        v-model="plandate2"
        type="daterange"
        style="margin:0 10px;"
        rangeSeparator="至"
        startPlaceholder="实际开始日期"
        endPlaceholder="实际开始日期"
        valueFormat="yyyy-MM-dd"
      ></el-date-picker> -->
      <el-button size="mini" type="primary" @click="getplanlist">搜索</el-button>
    </el-row>
    <el-divider></el-divider>
    <plantable2 :plantable="plantable" :pagobj="pagobj" :ischeck="false"></plantable2>
  </div>

</template>

<script>
import plantable2 from '~/components/person/workplan2/plantable2.vue';

export default {
  data() {
    return {
      ts: this.newStore(),
      searchData: {
        ttype: '',
        has_cert: '',
        tcontent: '',
        isbegin: '',
        pre_begintime_begin: '',
        pre_begintime_end: '',
        starttime_begin: '',
        starttime_end: '',
      },
      plantable: [],
      ttypeArr: [],
      classifyArr: [],
      pagobj: {
        currentPage3: 1,
        pagesize: 10,
        total: 10,
      },
      pre_beginyear: '',
      plandate: ['', ''],
      plandate2: ['', ''],
      ishashArr: [
        {
          label: '是',
          value: '1',
        },
        {
          label: '否',
          value: '0',
        },
      ],
      isbeginArr: [
        {
          label: '未开始',
          value: '0',
        },
        {
          label: '已开始',
          value: '1',
        },
      ],
    };
  },
  created() {
    this.getplanlist();
    this.getcodeData('0206', '02', 'ttypeArr');
    this.getcodeData('0207', '02', 'classifyArr');
    this.pre_beginyear = `${new Date().getFullYear()}`;
  },
  methods: {
    // 公共方法获取代码项
    getcodeData(supid, codetype, arrname) {
      const req = {
        handle: '67A5B6FEF17D97DECF116BDF95B95C0B167942DD3F1604F9',
        supid,
        codetype,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this[arrname] = ts.d.data.operation1;
      });
    },
    // 获取培训计划列表
    getplanlist() {
      // if (this.plandate == null) {
      //   this.plandate = [];
      // }
      // if (this.plandate2 == null) {
      //   this.plandate2 = [];
      // }
      const req = this.searchData;
      req.pre_beginyear = this.pre_beginyear;
      req.start = (this.pagobj.currentPage3 - 1) * this.pagobj.pagesize;
      req.limit = this.pagobj.pagesize;

      req.personid = localStorage.getItem('pid');
      req.person2id = localStorage.getItem('pid');
      req.handle = '33224548EFC2E94FE9F3B6004AA9373090D3E1223364DCF2BFF0B9210751F692';
      [req.pre_begintime_begin] = [this.plandate[0]];
      [req.pre_begintime_end] = [this.plandate[1]];
      [req.starttime_begin] = [this.plandate2[0]];
      [req.starttime_end] = [this.plandate2[1]];

      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.plantable = ts.d.data.operation1;
        this.pagobj.total = parseInt(ts.d.data.operation2[0].hash.allrs);
      });
    },
  },
  components: {
    plantable2,
  },
};
</script>

